<template>
	<div class="resaleAudiList content-wrap">
		<div class="content-top-box">
			<!-- 搜索区域 -->
			<ul class="search-container">
				<li>
					<span class="search-item-name">手机号：</span>
					<el-input class="search-item-content search-item-text" placeholder="请输入手机号" v-model="phone" clearable maxlength="11" @clear="clearPhoneFn">
					</el-input>
				</li>
				<li>
					<span class="search-item-name">姓名：</span>
					<el-input class="search-item-content search-item-text" placeholder="请输入姓名" v-model="userName" clearable @clear="clearUserName">
					</el-input>
				</li>
				<li>
					<span class="search-item-name">流水号：</span>
					<el-input class="search-item-content search-item-text" placeholder="请输入流水号" v-model="serialNumber" clearable @clear="clearUserName">
					</el-input>
				</li>
				<li>
					<span class="search-item-name">提现时间：</span>
					<el-date-picker v-model="payDate" type="daterange" range-separator="至" start-placeholder="开始时间" end-placeholder="结束时间" value-format="yyyy-MM-dd HH:mm:ss" @change="changePayDate">
					</el-date-picker>
				</li>
				<li>
					<span class="search-item-name">审核状态：</span>
					<el-select v-model="reviewCode" placeholder="请选择" clearable @change="changeBuyType">
						<el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value">
						</el-option>
					</el-select>
				</li> 
				<li>
					<el-button class="search-btn" type="primary" icon="el-icon-search" @click="searchFn" v-if="searchBtn">查询</el-button>
					<download-excel class="export-excel-wrapper" :data="jsonData" :fields="jsonFields" name="提现复审表.xls" v-if="exportBtn">
						<el-button class="search-btn" type="primary" icon="el-icon-download">导出</el-button>
					</download-excel>
				</li>
			</ul>
		</div>

		<div class="content-bottom-box">
			<!-- 表格 -->
			<div class="content-form-box">
				<el-table v-loading="loadingFlag" :data="tableData" :height="tableHeight" ref="table" border stripe style="width: 100%">
					<el-table-column prop="serialNumbers" label="序号" width="50" fixed>
					</el-table-column>
					<el-table-column prop="createTime" label="提现时间" width="180" fixed>
					</el-table-column>
					<el-table-column prop="userName" label="姓名" width="90">
					</el-table-column>
					<el-table-column prop="phone" label="手机号" width="140">
					</el-table-column>
					<el-table-column prop="txMoney" label="提现金额（元）" width="140">
					</el-table-column>
					<el-table-column prop="serviceFee" label="手续费（元）" width="120">
					</el-table-column>
					<el-table-column prop="dkMoney" label="打款金额（元）" width="130">
					</el-table-column>
					<el-table-column prop="bankName" label="银行名称" width="140" :show-overflow-tooltip="true">
					</el-table-column>
					<el-table-column prop="bankSub" label="开户支行" width="200" :show-overflow-tooltip="true">
					</el-table-column>
					<el-table-column prop="cardNumber" label="银行卡号" width="180" :show-overflow-tooltip="true">
					</el-table-column>
					<el-table-column prop="reviewCode" label="审核状态" width="160">
						<template slot-scope="scope">
							<span>
		                    	{{scope.row.reviewCode == '3' ? '初审不通过': '' 
								 || scope.row.reviewCode == '11' ? '待复审': '' 
								 || scope.row.reviewCode == '12' ? '复审通过 ': ''
								 || scope.row.reviewCode == '13' ? '复审不通过 ': ''
								}}
		                    </span>
						</template>
					</el-table-column>
					<el-table-column prop="accountMoney" label="账户余额" width="130">
					</el-table-column>
					<el-table-column prop="serialNumber" label="流水号" width="200">
					</el-table-column>
					<el-table-column prop="firstTrialTime" label="初审时间" width="200">
					</el-table-column>
					<el-table-column prop="firstTrialUser" label="初审人 " width="200">
					</el-table-column>
					<el-table-column prop="reviewTime" label="复审时间 " width="200">
					</el-table-column>
					<el-table-column prop="reviewUser" label="复审人 " width="200">
					</el-table-column>
					<el-table-column prop="reviewRemark" label="备注  " width="200">
					</el-table-column>
					<el-table-column label="操作" width="130" fixed="right" class-name="ccc">
						<template slot-scope="scope">
							<el-button @click="showDialog(scope.row)" type="text" size="small" disabled v-show="scope.row.reviewCode == 3 || scope.row.reviewCode == 12 || scope.row.reviewCode == 13" v-if="auditBtn">复审 </el-button>
							<el-button @click="showDialog(scope.row)" type="text" size="small" v-show="scope.row.reviewCode == 11" v-if="auditBtn">复审 </el-button>
							<el-button @click="checkResaleInfoFn(scope.row)" type="text" size="small" v-if="checkBtn">核对</el-button>
						</template>
					</el-table-column>
				</el-table>
			</div>

			<!-- 页码 -->
			<div class="content-Page-container">
				<BaseFormPage :pagination="pagination" @cFirstPageFn="cFirstPageFn" @cLastPageFn="cLastPageFn" @cJumpPageFn="cJumpPageFn" @cPreFn="cPreFn" @cNextFn="cNextFn" @cRefreshFn="cRefreshFn">
				</BaseFormPage>
			</div>
			<!-- 审核 -->
			<el-dialog title="提现复审" :visible.sync="dialogVisible" width="527px" :show-close="false" :close-on-click-modal="false" :close-on-press-escape="false" center>
				<div class="dialog-wrap">
					<p class="title">审核信息</p>
					<ul class="dialogList">
						<li>
							<span class="left">姓名</span>
							<span class="right">{{detailData.userName}}</span>
						</li>
						<li>
							<span class="left">手机号</span>
							<span class="right">{{detailData.phone}}</span>
						</li>
						<li>
							<span class="left">提现金额(元)</span>
							<span class="right">{{detailData.txMoney}}</span>
						</li>
						<li>
							<span class="left">手续费(元)</span>
							<span class="right">{{detailData.serviceFee}}</span>
						</li>
						<li>
							<span class="left">打款金额(元)</span>
							<span class="right">{{detailData.txMoney - detailData.serviceFee}}</span>
						</li>
						<li>
							<span class="left">银行卡号</span>
							<span class="right">{{detailData.cardNumber}}</span>
						</li>
						<li>
							<span class="left">银行名称</span>
							<span class="right">{{detailData.bankName}}</span>
						</li>
						<li>
							<span class="left">开户支行</span>
							<span class="right">{{detailData.bankSub}}</span>
						</li>
						<li>
							<span class="left">提现时间</span>
							<span class="right er-biao">{{detailData.createTime}}</span>
						</li>
						<el-form ref="ruleForm" :model="buyData" class="demo-ruleForm" labelPosition='right'>
							<li>
								<span class="left">处理</span>
								<span class="right">
									<el-form-item prop="reviewCode">
								  		<el-radio-group v-model="buyData.reviewCode" @change="selectState">
										    <el-radio label="12">复审通过</el-radio>
										    <el-radio label="13">复审不通过</el-radio>
										</el-radio-group>
									</el-form-item>
								</span>
							</li>
							<li>
								<span class="left">备注</span>
								<span class="right">
									<el-form-item prop="reviewRemark">
										<el-input placeholder="备注" v-model="buyData.reviewRemark" clearable class="reviewRemark"></el-input>
									</el-form-item>
								</span>
							</li>
						</el-form>
					</ul>
					<span slot="footer" class="dialog-footer">
						<el-button @click="cancelDialog('ruleForm')">取 消</el-button>
						<el-button type="primary" @click="keepDialog('ruleForm')">确 定</el-button>
					</span>
				</div>
			</el-dialog>
		
		</div>
	</div>
</template>

<script>
	import Storage from "@/utils/storage";
	import BaseFormPage from '@/components/BaseFormPage';
	export default {
		components: {
			BaseFormPage
		},
		inject: ['reload'],
		data() {
			return {
				dialogVisible: false, // 审核框
				loadingFlag: false, //表格数据加载状态
				phone: '',
				userName: '',
				startCreateTime: '',
				endCreateTime: '',
				serialNumber: '',
				reviewCode: '',
				buyData: {
					id: '',
					reviewCode: '',
					reviewUser: '',
					reviewRemark: ''
				},
				options: [
				{
					value: '2',
					label: '待复审'
				},{
					value: '3',
					label: '初审不通过'
				}, {
					value: '12',
					label: '复审通过'
				},{
					value: '13',
					label: '复审不通过'
				}],
				payDate: '',
				payState: '',
				pageIndex: 1,
				pageSize: 20,
				tableHeight: 200, //表格初始高度
				tableData: [], //表格数据
				pagination: { //分页数据
					loadingFlag: false, //数据加载状态
					currentPage: 1, //当前页
					totalPage: 1, //总页数
					totalNum: 0, //总条数
					firstNum: 0, //分页显示起始值
					endNum: 0 //分页显示结束值
				},
				jsonData: [],
				jsonFields: {
					"序号": "index",
					"提现时间": "applyTime",
					"姓名": "userName", 
					"手机号": "phone",
					"提现金额（元）": "txMoney",
					"手续费（元）": "serviceFee",
					"打款金额（元）": "dkMoney",
					"银行名称": "bankName",
					"开户支行": "bankSub",
					"银行卡号": "cardNumber",
					"审核状态 ": "reviewCode",
					"账户余额(元)": "accountMoney",
					"流水号": "serialNumber",
					"初审时间": "firstTrialTime",
					"初审人 ": "firstTrialUser",
					"复审时间": "reviewTime",
					"复审人": "reviewUser",
					"备注": "reviewRemark"
				},
				jsonMeta: [
					[{
						"key": "charset",
						"value": "utf-8"
					}]
				],
				detailData: {
					
				},

				searchBtn: (JSON.parse(Storage.get('roleAuthIdArr'))).indexOf(254) == -1 ? false : true,
				exportBtn: (JSON.parse(Storage.get('roleAuthIdArr'))).indexOf(255) == -1 ? false : true,
				auditBtn: (JSON.parse(Storage.get('roleAuthIdArr'))).indexOf(256) == -1 ? false : true,
				checkBtn: (JSON.parse(Storage.get('roleAuthIdArr'))).indexOf(257) == -1 ? false : true,
			}
		},
		created(){
			this.buyData.reviewUser = localStorage.getItem('nickName')
			
			this.getListData() 
		},
		methods: {
			getListData(){    // 审核列表
				this.loadingFlag = true;
				this.pagination.loadingFlag = true;
				let params = {
					phone: this.phone,
					userName: this.userName,
					serialNumber: this.serialNumber,
					reviewCode: this.reviewCode,
					startCreateTime: this.startCreateTime,
					endCreateTime: this.endCreateTime,
					pgCt: this.pageIndex,
					pgSz: this.pageSize
				}
				if(!this.phone) {
					delete params.phone
				}
				if(!this.userName) {
					delete params.userName
				}
				if(!this.serialNumber) {
					delete params.serialNumber
				}
				if(!this.reviewCode) {
					delete params.reviewCode
				}
				if(!this.startCreateTime) {
					delete params.startCreateTime
				}
				if(!this.endCreateTime) {
					delete params.endCreateTime
				}
				this.$http.get('/finance/listReview', params)
				.then((res)=>{
					console.log(res.data.records)
					if(res.data.records.length > 0) {
							this.pagination.totalPage = res.data.pages;
							this.pagination.totalNum = res.data.total;
							res.data.records.forEach((item, index) => {
								if(item.deliveryTime){
									item.deliveryTime = item.deliveryTime.split(' ')[0];
								}
								if(item.applyTime){
									item.applyTime = item.applyTime.replace('T', ' ')
								}
								item.dkMoney = item.txMoney - item.serviceFee;  // 打款金额
								//列表下标
								item.index = index
								//列表序号
								item.serialNumbers = ((this.pageIndex - 1) * this.pageSize) + (index + 1)
								//无数据处理
								item.reviewRemark = item.reviewRemark || '--'
//								item.auditTime = item.auditTime || '--'

							})
							this.pagination.firstNum = res.data.records[0].serialNumbers
							this.pagination.endNum = res.data.records[res.data.records.length - 1].serialNumbers
						} else {
							this.pagination.currentPage = 1
							this.pagination.totalPage = 1
							this.pagination.totalNum = 0
							this.pagination.firstNum = 0
							this.pagination.endNum = 0
						}
						this.tableData = res.data.records;
				})
				.then(() => {
						if(this.tableData.length !== 0) {
							this.tableHeightFn();
						}
						this.loadingFlag = false;
						this.pagination.loadingFlag = false;
						this.getAllListData()
					})
			},
			changePayDate() {
				if(this.payDate) {
					this.startCreateTime = this.payDate[0]
					this.endCreateTime = this.payDate[1].replace('00:00:00', '23:59:59')
				} else {
					this.startCreateTime = ''
					this.endCreateTime = ''
				}
				this.resetPageIndex()
				this.getListData()
			},
			changeBuyType(){
				this.resetPageIndex()
				this.getListData()
			},
			resetPageIndex() { //重置页码
				this.pagination.currentPage = 1;
				this.pageIndex = 1;
			},
			clearPhoneFn() { //清空手机号
				this.resetPageIndex()
				this.getListData()
			},
			clearUserName() { //清空姓名
				this.resetPageIndex()
				this.getListData()
			},
			searchFn() {
				this.resetPageIndex()
				this.getListData()
			},
			cFirstPageFn(pageNum) { //首页
				this.pageIndex = pageNum;
				this.getListData()
			},
			cLastPageFn(pageNum) { //尾页
				this.pageIndex = pageNum;
				this.getListData()
			},
			cJumpPageFn(pageNum) { //页码跳转
				this.pageIndex = pageNum;
				this.getListData()
			},
			cPreFn(pageNum) { //上一页
				this.pageIndex = pageNum;
				this.getListData()
			},
			cNextFn(pageNum) { //下一页
				this.pageIndex = pageNum;
				this.getListData()
			},
			resetParams() { //重置参数

			},
			cRefreshFn() { //刷新
				this.reload()
			},
			checkResaleInfoFn(item) { // 详情点击
				console.log(item)
				this.$router.push({
					path: '/balanceList',
					query: {
						userName: item.userName
					}
				})
			},
			selectState(value) {
				console.log(value)
				this.buyData.reviewCode = value;
			},
			showDialog(item) {
				console.log(item)
				this.detailData = item;
				this.buyData.id = item.id;
				this.dialogVisible = true;
			},
			cancelDialog(formName) {
				this.dialogVisible = false;
				this.$refs[formName].resetFields();
			},
			keepDialog(formName) {  // 确认
				if(this.buyData.reviewCode){
					this.$http.get('/finance/updateReview', this.buyData)
					.then((res)=>{
						console.log(res)
						if(res.data == 200){
							this.dialogVisible = false;
							this.getListData();
							this.$refs[formName].resetFields();
						}
					})
				} else {
					this.$message({
			          message: '请选择处理状态',
			          type: 'warning',
			          offset: '70'
			        })
				}
			},
			tableHeightFn() { //表格高度
				let tableDataLength = this.tableData.length;
				let minHeight = tableDataLength == 0 ? 0 : 80; //根据需求距离底部的高度
				this.$nextTick(function() {
					//window.innerHeight:浏览器的可用高度
					//this.$refs.table.$el.offsetTop：表格距离浏览器的高度
					this.tableHeight = window.innerHeight - this.$refs.table.$el.offsetTop - minHeight;
					if(this.tableData.length <= 0) {
						this.tableHeight = '60vh'
					}

					// 通过捕获系统的onresize事件触发去改变原有的高度
					let self = this;
					window.onresize = function() {
						self.tableHeight = window.innerHeight - self.$refs.table.$el.offsetTop - minHeight;
						self.tableHeight = self.tableHeight < 200 ? 200 : self.tableHeight;
					}
				})
			},
			getAllListData(){   
				let params = {
					phone: this.phone,
					userName: this.userName,
					serialNumber: this.serialNumber,
					reviewCode: this.reviewCode,
					startCreateTime: this.startCreateTime,
					endCreateTime: this.endCreateTime,
					pgCt: 1,
					pgSz: 99999
				}
				if(!this.phone) {
					delete params.phone
				}
				if(!this.userName) {
					delete params.userName
				}
				if(!this.serialNumber) {
					delete params.serialNumber
				}
				if(!this.reviewCode) {
					delete params.reviewCode
				}
				if(!this.startCreateTime) {
					delete params.startCreateTime
				}
				if(!this.endCreateTime) {
					delete params.endCreateTime
				}
				this.$http.get('/finance/listReview', params)
				.then((res)=>{
					console.log(res)
					if(res.data.records.length > 0) {
							res.data.records.forEach((item, index) => {
								if(item.deliveryTime){
									item.deliveryTime = item.deliveryTime.split(' ')[0];
								}
								if(item.applyTime){
									item.applyTime = item.applyTime.replace('T', ' ')
								}
								item.dkMoney = item.txMoney - item.serviceFee;  // 打款金额
								if(item.reviewCode == 3){
									item.reviewCode = '初审不通过'
								} else if(item.reviewCode == 2){
									item.reviewCode = '待复审'	
								} else if(item.reviewCode == 12 || item.reviewCode == 11){
									item.reviewCode = '复审通过'	
								} else if(item.reviewCode == 13){
									item.reviewCode = '复审不通过'	
								}
								//列表下标
								item.index = index + 1
								//无数据处理
							})
						}
						this.jsonData = res.data.records;
				})
			},
		},

	}
</script>
<style type="text/css">
	.resaleAudiList .dialog-wrap .el-input__inner,.resaleAudiList .dialog-wrap .el-textarea__inner {
		border-color: #fff !important;
	}
	.resaleAudiList .dialog-wrap .el-form-item{
		margin-bottom: 0;
	}
	.resaleAudiList .dialog-wrap .el-form-item__error{
		z-index: 9;
	}
	.ccc .cell{
		display: flex;
		justify-content: space-between;
		padding: 0 20px;
	}
	.ccc .el-button + .el-button{
		margin-left: 0;
	}
	.resaleAudiList .reviewRemark input{
		padding-left: 0;
	}
</style>
<style lang="scss" scoped>
@import '@/assets/css/dialogDetail.scss';
.last-oli{
		display: inherit; 
		padding-left: 74px;
		position: relative;
		.last-ospan{
			position: absolute;
			left: 0;
			top: 0;
		}
		.last-span2{
			position: absolute;
			left: 145px;
			top: 0;
		}
	}
	
</style>